// pages/my/auditject/auditject.js
Page({
  data: {
    taskId: "",
    historyId: "",
    reviewStatus: "",
    message: "",
    fileList: [],
    imgIds: [],
  },
  onLoad: function (options) {
    this.setData({
      taskId: options.taskId,
      historyId: options.historyId,
      reviewStatus: options.reviewStatus
    });
  },
  upload(e) {
    getApp().globalData.util.imgsUpload(this, e, this.data.fileList, this.data.imgIds);
  },
  delete(e) {
    let i = e.detail.index;
    let fileList = this.data.fileList;
    let imgIds = this.data.imgIds;
    fileList.splice(i, 1);
    imgIds.splice(i, 1);
    this.setData({
      fileList: fileList,
      imgIds: imgIds
    });
  },
  submit() {
    let params = null;
    if (this.data.reviewStatus == 1) {
      params = {
        id: this.data.taskId,
        historyId: this.data.historyId,
        reviewStatus: this.data.reviewStatus,
        firstReviewContent: this.data.message,
        firstReviewImgIds: this.data.imgIds.join(",")
      };
    } else if (this.data.reviewStatus == 4) {
      params = {
        id: this.data.taskId,
        historyId: this.data.historyId,
        reviewStatus: this.data.reviewStatus,
        secondReviewContent: this.data.message,
        secondReviewImgIds: this.data.imgIds.join(",")
      };
    }
    if (!this.data.message) {
      getApp().globalData.vant.toast("请输入拒绝理由");
    } else {
      getApp().globalData.http.evidence(params).then(res => {
        getApp().globalData.vant.toast({
          type: "success",
          message: "提交成功",
          duration: 1000,
          onClose: () => {
            wx.navigateBack({
              delta: 0,
              success: function (e) {
                var page = getCurrentPages().pop();
                if (page == undefined || page == null) return;
                page.getData();
              }
            });
          },
        });
      });
    }
  }
})